from fastapi import FastAPI
import uvicorn
from configparser import ConfigParser
from starlette.middleware.cors import CORSMiddleware

app = FastAPI(title="应急资源测试API"
              , description="内部系统接口"
              , version= '0.2.0')

# 跨域 , 允许所有
origins = ["*"]
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,  #设置允许的origins来源
    allow_credentials=True,
    allow_methods=["*"],  # 设置允许跨域的http方法，比如 get、post、put等。
    allow_headers=["*"]  #允许跨域的headers，可以用来鉴别来源等作用。
)

# default
uvicorn_host='127.0.0.1'
uvicorn_port=8000

config = ConfigParser()
config.read('config.ini')
uvicorn_config = config['uvicorn']
uvicorn_host = uvicorn_config['host']
uvicorn_port = int(uvicorn_config['port'])


@app.get("/VideoServer/dahuaDss/getOrg.json", summary= "获取机构列表")
def getOrg():
    return {
        "requestParam": {
            "superiorId": None,
            "chanelId": None,
            "scheme": None
        },
        "requestResult": {
            "result": True,
            "message": None,
            "ortherId": 0,
            "data": [
                {
                    "name": "高栏港应急监控系统",
                    "id": "S4NbecfYB1C62G1ODDS8N4",
                    "devices": [],
                    "childs": [
                        {
                            "name": "汇华管廊",
                            "id": "S4NbecfYB1C62GP23PERN4",
                            "devices": [
                                {
                                    "id": "n9WDBEhrA1C7K2JTN4559F",
                                    "name": "机房",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53LTK",
                                    "name": "运行管理中心",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53M39",
                                    "name": "大堂",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53M4C",
                                    "name": "二楼走廊",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53M92",
                                    "name": "三楼走廊",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53MCA",
                                    "name": "西北方向",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53ME0",
                                    "name": "西南方向",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53MHT",
                                    "name": "东南方向",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53MM5",
                                    "name": "大门",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53MPB",
                                    "name": "一楼走廊",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53MQD",
                                    "name": "厨房",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K2JTN53MTC",
                                    "name": "运行仓库",
                                    "online": 1
                                }
                            ],
                            "childs": None
                        },
                        {
                            "name": "安检中心",
                            "id": "S4NbecfYB1C7F1917LDCB4",
                            "devices": [
                                {
                                    "id": "n9WDBEhrA1C7K2JTN36II3",
                                    "name": "环岛路-G4-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9S0PSH",
                                    "name": "风鹰一路-G16-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9S0Q3K",
                                    "name": "平排四路-G15-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9S0Q9E",
                                    "name": "南迳中路-G17-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9S0QH5",
                                    "name": "风鹰南路-G19-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9S0QLI",
                                    "name": "风鹰南路-G19-球机2",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9S0QTM",
                                    "name": "风鹰南路-G20-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9SVBLG",
                                    "name": "风鹰南路-G20-球机2",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9SVBQO",
                                    "name": "风鹰北路-G24-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9SVC20",
                                    "name": "风鹰北路-G24-球机2",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9SVC83",
                                    "name": "风鹰北路-G25-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9SVCFQ",
                                    "name": "风鹰北路-G25-球机2",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9SVCKB",
                                    "name": "南迳东路-G28-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9TTTE5",
                                    "name": "南迳东路-G28-球机2",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9TTTK9",
                                    "name": "南迳东路-G29-球机1",
                                    "online": 1
                                },
                                {
                                    "id": "n9WDBEhrA1C7K6AE9TTTP8",
                                    "name": "南迳东路-G29-球机2",
                                    "online": 1
                                }
                            ],
                            "childs": None
                        },
                        {
                            "name": "高栏港大厦",
                            "id": "S4NbecfYB1C7HMDKDGSRO8",
                            "devices": [
                                {
                                    "id": "n9WDBEhrA1C7K6AE9R28JL",
                                    "name": "IP PTZ Camera",
                                    "online": 1
                                }
                            ],
                            "childs": None
                        }
                    ]
                }
            ]
        }
    }

@app.get("/VideoServer/dahuaDss/getPlayUrl.json", summary= "获取视频实时播放url")
def getPlayUrl(chanelId : str, scheme : str):
    return  {
        "requestParam": {
            "superiorId": None,
            "chanelId": chanelId,
            "scheme": scheme
        },
        "requestResult": {
            "result": True,
            "message": None,
            "ortherId": 0,
            "data": "http://10.24.66.247:8050/cam/realmonitor/n9WDBEhrA1C7K2JTN53MM5?subtype=0&streamType=0&token=1594231197_fe413db2d15ab4f134ea64e8eb347db1b53d3eea&mediatype=HLS.m3u8"
        }
    }


@app.get("/specialist/toViewSpecialistPage.action", summary= "专家详情")
def get_special_detail(id: str, ajax: str):
    return  {
        "errorCode": 1000,
        "errorMsg": "查询成功(测试 API), ajax: " + ajax,
        "data": {
            "id": id,
            "sp_name": "余薇龙",
            "typeCode": "自然灾害类",
            "levelCode": "",
            "sex": "男",
            "birthday": "1968-11-01 00:00:00",
            "nation": "汉",
            "dept_id": "1",
            "placeunit": "高栏港分局防火监督大队",
            "titles": "助理工程师",
            "position": "科长",
            "researchArea": "",
            "expertise": "",
            "mobile": "13702947400",
            "telOffice": "",
            "cardNo": "440254199411132564",
            "hometown": "中国",
            "homeAddr": "中国",
            "politicalLandscapeCode": "中共党员",
            "health": "良好",
            "degreeCode": "珠海",
            "graduateFrom": "珠海",
            "householdRegisterAddr": "珠海",
            "resume": "",
            "achievement": "",
            "experience": "",
            "lastUpdated": "2020-12-31 00:00:00",
            "detail": "",
            "name": "高栏港保障部1",
            "rowStart": 0,
            "totalRows": 0,
            "rowSize": 0
        }
    }

@app.get("/rescueteam/toViewRescueteamPage.action", summary= "队伍详情")
def get_rescueteam_detail( id: str, ajax: str):
    return {
        "errorCode": 1000,
        "errorMsg": "查询成功(测试 API), ajax:" + ajax,
        "data": {
            "id": id,
            "rs_name": "高栏海关应急小分队",
            "addr": "广东省珠海市高栏港",
            "communicateType": "电话",
            "departure": "",
            "dept_id": "1",
            "equipments": "",
            "fax": "",
            "fundationDate": "1999-12-31 00:00:00",
            "level_code": "",
            "needSupport": "",
            "personInCharge": "胡戡",
            "personInCharge_tel": "15907569897",
            "competent_org": "高栏海关",
            "personInCharge_officetel": "",
            "personToContact": "胡戡",
            "personToContact_officetel": "",
            "personToContact_tel": "15907569897",
            "responsibilities": "",
            "rescueExperience": "",
            "qualificationLevel": "",
            "specialty": "",
            "tel": "",
            "total": "20",
            "trafficTools": "",
            "typecode": "综合类",
            "zipCode": "",
            "levelid": "县级",
            "resourceType": "兼职",
            "x": "113.577139",
            "y": "22.276268",
            "detail": "",
            "ribbon_code": "",
            "name": "高栏港保障部1",
            "rowStart": 0,
            "totalRows": 0,
            "rowSize": 0
        }
    }

@app.get("/shelter/toViewShelterPage.action", summary = "避难场所详情")
def get_shelter_detail(id: str):
    return {
        "errorCode": 1000,
        "errorMsg": "查询成功(测试 API)",
        "data": {
            "id": id,
            "s_name": "平塘卫生服务中心" + id,
            "addr": "珠海市高栏港平沙镇平塘卫生服务中心",
            "area": "",
            "baseinfo": "",
            "communicateType": "",
            "contentPeopleNum": "",
            "dept_id": "1",
            "designYears": "",
            "detail": "",
            "fax": "",
            "intensity": "",
            "last_updated": "2020-03-31 00:00:00",
            "feat": "医疗服务保障",
            "tag": "0",
            "kit": "配备有氧气、消防灭火器",
            "tel": "",
            "travelInfo": "",
            "type_Code": "",
            "level_id": "区级",
            "type_id": "",
            "X": "113.205461",
            "Y": "22.113159",
            "Personincharge": "潘颖华",
            "Personincharge_tel": "13411382813",
            "personinContact_officetel": "医生",
            "Personoutcharge": "潘颖华",
            "Personoutcharge_tel": "13411382813",
            "personToContact_officetel": "医生",
            "outintstatus": "室内",
            "org": {
                "pid": None,
                "isParent": None,
                "id": None,
                "name": "高栏港保障部1",
                "openID": None,
                "createTime": None,
                "lastUpdateTime": None,
                "lastUpdateOpenID": None
            },
            "rowStart": 0,
            "totalRows": 0,
            "rowSize": 0
        }
    }

@app.get("/lgywsoft/planText/getTitleList.action", summary="预案-详情-标题")
def get_plan_text_detail_title(id: str):
    return {
        "errorCode": 1000,
        "errorMsg": "查询成功(测试 API)",
        "data": [
            {
                "title": "1.1 目的",
                "order_by": "1"
            },
            {
                "title": "1.2适用范围",
                "order_by": "2"
            },
            {
                "title": "2.1 应急组织体系",
                "order_by": "4"
            },
            {
                "title": "2.2 区应急指挥中心机构及成员职责",
                "order_by": "5"
            },
            {
                "title": "2.3 应急救援现场指挥部机构及职责",
                "order_by": "6"
            },
            {
                "title": "3.1 应急报告",
                "order_by": "8"
            },
            {
                "title": "3.2 应急处置",
                "order_by": "9"
            },
            {
                "title": "3.3 扩大应急",
                "order_by": "10"
            },
            {
                "title": "4. 应急终止",
                "order_by": "11"
            }
        ]
    }

@app.get("/warehouse/toViewWarehousePage.action", summary="应急物资-仓库详情", description="暂无描述")
def get_warehouse_detail(id: str):
    return {
        "errorCode": 1000,
        "errorMsg": "查询成功 测试API服务",
        "data": {
            "id": id,
            "w_name": id + " 处基地码头1",
            "addr": "高栏港临港一路89号",
            "dept_id": "1",
            "last_updated": "2020-06-09 09:06:04",
            "operator": "肖俊林",
            "operator_code": "13926938578",
            "inspector": "肖俊林",
            "inspector_code": "13926938578",
            "x": "113.845033",
            "y": "22.768231",
            "level": "市级",
            "competent_org": "",
            "org": {
                "pid": None,
                "isParent": None,
                "id": None,
                "name": "高栏港保障部1",
                "openID": None,
                "createTime": None,
                "lastUpdateTime": None,
                "lastUpdateOpenID": None
            },
            "rowStart": 0,
            "totalRows": 0,
            "rowSize": 0
        }
    }

@app.get("/warehousematerial/toViewWarehousematerialPage.action", summary="应急物资-物资详情")
def warehousematerial_detail(id):
    if id:
        return {
        "errorCode": 1000,
        "errorMsg": "查询成功",
        "data": {
            "id": id,
            "material_id": "129",
            "warehouse_id": "49",
            "amounts": "1",
            "totalmoney": "",
            "dept_id": "1",
            "Flot": "",
            "lastUpdate": "2020-05-13 00:00:00",
            "createTime": "0002-12-31 00:00:00",
            "Addr": "南水镇南港路13号",
            "operator": "黄机敏",
            "operator_code": "13928072456",
            "inspector": "黄机敏",
            "inspector_code": "13928072456",
            "StockIn": "",
            "storetype": "实物储备",
            "remark": "",
            "unit": "台",
            "material": 1,
            "m_name": id + " 飞鹰2106烟雾机",
            "warehouse": None,
            "w_name": "防保科",
            "org": {
                "pid": None,
                "isParent": None,
                "id": None,
                "name": "高栏港保障部1",
                "openID": None,
                "createTime": None,
                "lastUpdateTime": None,
                "lastUpdateOpenID": None
            },
            "status": "可正常使用",
            "facturer": "美国丹拿",
            "m_type": "",
            "govern_org": "（南水镇）卫生院",
            "num": 0,
            "rowStart": 0,
            "totalRows": 0,
            "rowSize": 0
        }
    }
    else:
        return {
            "errorCode": 1001,
            "errorMsg": "参数不能为空",
            "data": None
        }

@app.get("/lgywsoft/dg/getDetailByParam.action", summary="获取危化品详情")
def detail_by_param(id):
    return  {
        "errorCode": 1000,
        "errorMsg": "查询成功(测试API)",
        "data": {
            "id": id,
            "chemicalName": "氯酸钠（Sodium chlorate）。别称：氯酸碱、白药钠、氯酸鲁达。\n",
            "emergency": "CS-SZG-1070-氯酸钠应急处置",
            "num": "CS-SZG-1070",
            "propertiesAndUse": "1、理化性质：通常为白色或微黄色等轴晶体。味咸而凉，易溶于水、微溶于乙醇。在酸性溶液中有强氧化作用，300℃ 以上分解出氧气。\n2、稳定性和危险性：氯酸钠不稳定。与磷、硫及有机物混合受撞击时易发生燃烧和爆炸，易吸潮结块。\n3、毒理学指标：低毒性。\n4、主要用途：工业上主要用于制造二氧化氯、亚氯酸钠、高氯酸盐及其它氯酸盐。",
            "safety": "呼吸系统防护：可能接触其粉尘时，建议佩戴自吸过滤式防尘口罩。\n眼睛防护：戴化学安全防护眼镜。\n身体防护：穿聚乙烯防毒服。\n手防护：戴橡胶手套。\n其它：工作现场禁止吸烟、进食和饮水。工作毕，淋浴更衣。保持良好的卫生习惯。",

            "rowStart": 0,
            "totalRows": 0,
            "rowSize": 0
        }
    }


def run():
    uvicorn.run("layer_api:app", port=uvicorn_port, reload = True, host=uvicorn_host)

if __name__ == '__main__':
    run()